{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "\u001b[32m2024-07-22 18:44:30.230\u001b[0m | \u001b[1mINFO    \u001b[0m | \u001b[36mbyzerllm.utils.connect_ray\u001b[0m:\u001b[36mconnect_cluster\u001b[0m:\u001b[36m48\u001b[0m - \u001b[1mJDK 21 will be used (/Users/allwefantasy/.auto-coder/jdk-21.0.2.jdk/Contents/Home)...\u001b[0m\n",
      "2024-07-22 18:44:30,286\tINFO worker.py:1564 -- Connecting to existing Ray cluster at address: 127.0.0.1:6379...\n",
      "2024-07-22 18:44:30,287\tINFO worker.py:1582 -- Calling ray.init() again after it has already been called.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<<<<<<< SEARCH\n",
      "## 使用\n",
      "\n",
      "\n",
      "=======\n",
      "## 使用\n",
      "\n",
      "安装完成后，您可以使用 `image2txt` 命令来转换图片为文本描述。以下是基本用法：\n",
      "\n",
      "```\n",
      "image2txt --images path/to/image1.jpg,path/to/image2.png --output results.json\n",
      "```\n",
      "\n",
      "### 参数说明\n",
      "\n",
      "- `--images`: 要处理的图片路径，多个图片用逗号分隔\n",
      "- `--output`: （可选）输出结果的 JSON 文件路径\n",
      "\n",
      "### 示例\n",
      "\n",
      "1. 处理单张图片：\n",
      "\n",
      "```\n",
      "image2txt --images path/to/image.jpg\n",
      "```\n",
      "\n",
      "2. 处理多张图片：\n",
      "\n",
      "```\n",
      "image2txt --images path/to/image1.jpg,path/to/image2.png,path/to/image3.jpg\n",
      "```\n",
      "\n",
      "3. 处理图片并保存结果到 JSON 文件：\n",
      "\n",
      "```\n",
      "image2txt --images path/to/image1.jpg,path/to/image2.png --output results.json\n",
      "```\n",
      "\n",
      "### 输出\n",
      "\n",
      "程序会在控制台打印每张图片的描述，如果指定了 `--output` 参数，还会将结果保存到指定的 JSON 文件中。\n",
      "\n",
      "JSON 文件的格式如下：\n",
      "\n",
      "```json\n",
      "[\n",
      "  {\n",
      "    \"image_path\": \"path/to/image1.jpg\",\n",
      "    \"description\": \"图片的文本描述\"\n",
      "  },\n",
      "  {\n",
      "    \"image_path\": \"path/to/image2.png\",\n",
      "    \"description\": \"图片的文本描述\"\n",
      "  }\n",
      "]\n",
      "```\n",
      "\n",
      "注意：首次运行时，程序会自动检查并部署所需的模型，这可能需要一些时间。后续运行将会更快。\n",
      "\n",
      ">>>>>>> REPLACE\n"
     ]
    }
   ],
   "source": [
    "from autocoder.common.anything2images import AutoCoderArgs\n",
    "from autocoder.common.code_auto_merge_editblock import CodeAutoMergeEditBlock\n",
    "import byzerllm\n",
    "\n",
    "llm = byzerllm.ByzerLLM.from_default_model(\"deepseek_chat\")\n",
    "args = AutoCoderArgs()\n",
    "m = CodeAutoMergeEditBlock(llm=llm, args=args)\n",
    "\n",
    "k = m.parse_whole_text('''\n",
    "为了完善 README.md 的使用部分，我们需要修改 `/Users/allwefantasy/projects/image2text/README.md` 文件。以下是相应的 *SEARCH/REPLACE* 块：\n",
    "\n",
    "```markdown\n",
    "##File: /Users/allwefantasy/projects/image2text/README.md\n",
    "<<<<<<< SEARCH\n",
    "## 使用\n",
    "\n",
    "\n",
    "=======\n",
    "## 使用\n",
    "\n",
    "安装完成后，您可以使用 `image2txt` 命令来转换图片为文本描述。以下是基本用法：\n",
    "\n",
    "```\n",
    "image2txt --images path/to/image1.jpg,path/to/image2.png --output results.json\n",
    "```\n",
    "\n",
    "### 参数说明\n",
    "\n",
    "- `--images`: 要处理的图片路径，多个图片用逗号分隔\n",
    "- `--output`: （可选）输出结果的 JSON 文件路径\n",
    "\n",
    "### 示例\n",
    "\n",
    "1. 处理单张图片：\n",
    "\n",
    "```\n",
    "image2txt --images path/to/image.jpg\n",
    "```\n",
    "\n",
    "2. 处理多张图片：\n",
    "\n",
    "```\n",
    "image2txt --images path/to/image1.jpg,path/to/image2.png,path/to/image3.jpg\n",
    "```\n",
    "\n",
    "3. 处理图片并保存结果到 JSON 文件：\n",
    "\n",
    "```\n",
    "image2txt --images path/to/image1.jpg,path/to/image2.png --output results.json\n",
    "```\n",
    "\n",
    "### 输出\n",
    "\n",
    "程序会在控制台打印每张图片的描述，如果指定了 `--output` 参数，还会将结果保存到指定的 JSON 文件中。\n",
    "\n",
    "JSON 文件的格式如下：\n",
    "\n",
    "```json\n",
    "[\n",
    "  {\n",
    "    \"image_path\": \"path/to/image1.jpg\",\n",
    "    \"description\": \"图片的文本描述\"\n",
    "  },\n",
    "  {\n",
    "    \"image_path\": \"path/to/image2.png\",\n",
    "    \"description\": \"图片的文本描述\"\n",
    "  }\n",
    "]\n",
    "```\n",
    "\n",
    "注意：首次运行时，程序会自动检查并部署所需的模型，这可能需要一些时间。后续运行将会更快。\n",
    "\n",
    ">>>>>>> REPLACE\n",
    "```\n",
    "\n",
    "这个修改添加了以下内容到 README.md 文件的使用部分：\n",
    "\n",
    "1. 基本用法说明\n",
    "2. 命令行参数的详细解释\n",
    "3. 不同使用场景的示例\n",
    "4. 输出格式的说明，包括控制台输出和 JSON 文件输出\n",
    "5. 关于首次运行时模型部署的提示\n",
    "\n",
    "这些信息应该能够帮助用户更好地理解如何使用 `image2txt` 工具。\n",
    "''')\n",
    "\n",
    "for i in k:\n",
    "    print(i.content)\n",
    "    "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "byzerllm",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
